package com.kyub.buganville

import grails.test.*
import grails.plugins.springsecurity.SpringSecurityService
import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser


class DashboardControllerTests extends ControllerUnitTestCase {



  protected void setUp() {
    super.setUp()

    def user = new User(username: 'me', enabled: true, password: 'password')
    mockDomain(User, [user])
    def artifact = new Artifact(name: "demo artifact", description: "Demo demo demo")
    mockDomain(Artifact, [artifact])
   
    Issue iok = new Issue(title: "Test Issue", content: "SBIDIGUDA SBIDIGUDA", priority: Priority.HIGH, status: IssueStatus.OPEN, type: IssueType.BLOCKER, opener: user, artifact: artifact,asegnee:user)
    mockDomain(Issue, [iok])
  }

  protected void tearDown() {
    super.tearDown()
  }

  void testIndex() {

    DashboardController controller = new DashboardController();
    def mock = mockFor(SpringSecurityService)
    mock.demand.getPrincipal(1..1)  { -> return new GrailsUser('me','pass',true,true,true,true,[],'1')} 
    controller.springSecurityService = mock.createMock()
    def model = controller.index()
    assertNotNull(model.issues)

  }
}
